package com.volunteer.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.volunteer.common.R;
import com.volunteer.entity.Comment;
import com.volunteer.model.vo.ActivityDetailVO;
import com.volunteer.model.vo.CommentVO;
import com.volunteer.service.ActivityService;
import com.volunteer.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * 活动控制器
 */
@Tag(name = "评论接口管理")
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;


    /**
     * 获取活动评论列表
     *
     * @param activityId 活动ID
     * @return 评论列表
     */
    @Operation(summary = "获取活动评论列表")
    @GetMapping("/list/{activityId}")
    public R<List<CommentVO>> getComments(@Parameter(description = "活动ID") @PathVariable Long activityId) {
        List<CommentVO> comments = commentService.getComments(activityId);
        return R.ok(comments);
    }

    /**
     * 发表评论
     *
     * @return 操作结果
     */
    @Operation(summary = "发表评论")
    @PostMapping("/create")
    public R<Boolean> createComment(@RequestBody Comment comment) {
        Long userId = StpUtil.getLoginIdAsLong();
        boolean result = commentService.createComment(comment.getActivityId(), comment.getParentId(), userId, comment.getContent());
        return R.ok(result);
    }

    /**
     * 点赞评论
     *
     * @param commentId 评论ID
     * @return 操作结果
     */
    @Operation(summary = "点赞评论")
    @PostMapping("/like/{commentId}")
    public R<Boolean> likeComment(@Parameter(description = "评论ID") @PathVariable Long commentId) {
        Long userId = StpUtil.getLoginIdAsLong();
        boolean result = commentService.likeComment(commentId, userId);
        return R.ok(result);
    }

    /**
     * 删除评论
     *
     * @param commentId 评论ID
     * @return 操作结果
     */
    @Operation(summary = "删除评论")
    @DeleteMapping("/delete/{commentId}")
    public R<Boolean> deleteComment(@Parameter(description = "评论ID") @PathVariable Long commentId) {
        Long userId = StpUtil.getLoginIdAsLong();
        boolean result = commentService.deleteComment(commentId, userId);
        return R.ok(result);
    }
}
